﻿using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPNextHelper
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            

            //输入输出EXCEL文件名
            string file_in = "d:\\科目表.xlsx";
            if(args.Length > 0)
            {
                file_in = args[0];
            }
            string file_out = Path.GetFileNameWithoutExtension(file_in);
            file_out =Path.Combine(Path.GetDirectoryName(file_in),$"{file_out}_out.xlsx");            

            //读入EXCEL
            var accounts=Account_Excel.ReadFromExcelFile(file_in);

            //计算父子关系
            accounts=Account_Excel.MakeOrderedList(accounts);
            var root=Account_Excel.SetAllPrents(accounts);
            Account_Excel.MakeLftRgt(root);

            //输出EXCEL
            Account_Excel.WriteToExcelFile(file_out, accounts);

        }
    }
}
